package com.example.naodian.context;

public class BaseContext {

    // 分别为用户ID和角色创建独立的ThreadLocal变量
    private static final ThreadLocal<Long> userIdHolder = new ThreadLocal<>();
    private static final ThreadLocal<Long> roleHolder = new ThreadLocal<>();

    // 设置用户ID
    public static void setCurrentId(Long id) {
        userIdHolder.set(id);
    }

    // 获取用户ID
    public static Long getCurrentId() {
        return userIdHolder.get();
    }

    // 移除用户ID
    public static void removeCurrentId() {
        userIdHolder.remove();
    }

    // 设置角色
    public static void setCurrentRole(Long role) {
        roleHolder.set(role);
    }

    // 获取角色
    public static Long getCurrentRole() {
        return roleHolder.get();
    }

    // 移除角色
    public static void removeCurrentRole() {
        roleHolder.remove();
    }
}
